package com.ltv.xiangqiplugin.models;

import java.util.Vector;

public class Xiang extends Piece { // Elephant
	private static Xiang xiang;

	private Xiang() {
	}

	public static Vector<Destination> possibleDestinations(char [][] board, SquareCoord origin, boolean checkCheck) {
		if (xiang == null) {
			xiang = new Xiang();
		}

		return xiang._possibleDestinations(board, origin, checkCheck);
	}

	private Vector<Destination> _possibleDestinations(char [][] board, SquareCoord origin, boolean checkCheck) {
		Vector<Destination> moves = new Vector<Destination>();
		int x = origin.getRow();
		int y = origin.getFile();
		char piece = board[x][y];
		char [][] tempBoard = fillTempBoard(board);
		tempBoard[x][y] = ' ';
		char color = ' ';

		if (Character.isUpperCase(board[x][y])) {
			color = 'r';
		} else {
			color = 'b';
		}

		if ((color == 'r' && x+2 < 5) || (color == 'b' && x+2 < 10)) {
			if ((y-2 > -1) && board[x+1][y-1] == ' ') {
				checkMove(moves, x+2, y-2, piece, color, tempBoard, board, checkCheck);
			}
			if ((y+2 < 9) && board[x+1][y+1] == ' ') {
				checkMove(moves, x+2, y+2, piece, color, tempBoard, board, checkCheck);
			}
		}

		if ((color == 'r' && x-2 > -1) || (color == 'b' && x-2 > 4)) {
			if ((y-2 > -1) && board[x-1][y-1] == ' ') {
				checkMove(moves, x-2, y-2, piece, color, tempBoard, board, checkCheck);
			}
			if ((y+2 < 9) && board[x-1][y+1] == ' ') {
				checkMove(moves, x-2, y+2, piece, color, tempBoard, board, checkCheck);
			}
		}

		return moves;
	}
}
